home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Information / Digests / CSMP Digest / volume 3 / csmp-digest-v3-038 / doubleCR.1 < prev   
Encoding:
Text File  |  1995-12-31  |  40.2 KB  |  1,138 lines

  1. C.S.M.P. Digest             Tue, 21 Jun 94       Volume 3 : Issue 38
  2.  
  3. Today's Topics:
  4.  
  5.         CopyBits with PixMap
  6.         Gestalt, SU3.0 & List Manager
  7.         How to tell what kind of drive a volume is?
  8.         Photoshop Plug-in Filters useable with other programs?
  9.         Scheduling Sleep in WaitNextEvent
  10.         What is "Clipping Extension"?
  11.         allocating memory quickly -- how?
  12.         sqrti() [Re: Faster Square Root Algorithm]
  13.  
  14.  
  15.  
  16. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  17. (pottier@clipper.ens.fr).
  18.  
  19. The digest is a collection of article threads from the internet newsgroup
  20. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  21. regularly and want an archive of the discussions.  If you don't know what a
  22. newsgroup is, you probably don't have access to it.  Ask your systems
  23. administrator(s) for details.  If you don't have access to news, you may
  24. still be able to post messages to the group by using a mail server like
  25. anon.penet.fi (mail help@anon.penet.fi for more information).
  26.  
  27. Each issue of the digest contains one or more sets of articles (called
  28. threads), with each set corresponding to a 'discussion' of a particular
  29. subject.  The articles are not edited; all articles included in this digest
  30. are in their original posted form (as received by our news server at
  31. nef.ens.fr).  Article threads are not added to the digest until the last
  32. article added to the thread is at least two weeks old (this is to ensure that
  33. the thread is dead before adding it to the digest).  Article threads that
  34. consist of only one message are generally not included in the digest.
  35.  
  36. The digest is officially distributed by two means, by email and ftp.
  37.  
  38. If you want to receive the digest by mail, send email to listserv@ens.fr
  39. with no subject and one of the following commands as body:
  40.     help                        Sends you a summary of commands
  41.     subscribe csmp-digest Your Name    Adds you to the mailing list
  42.     signoff csmp-digest            Removes you from the list
  43. Once you have subscribed, you will automatically receive each new
  44. issue as it is created.
  45.  
  46. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  47. Questions related to the ftp site should be directed to
  48. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  49. digest are available there.
  50.  
  51. Also, the digests are available to WAIS users.  To search back issues
  52. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  53. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  54.  
  55.  
  56. -------------------------------------------------------
  57.  
  58. >From ragatz@nevada.edu (Steven Ragatz)
  59. Subject: CopyBits with PixMap
  60. Date: 5 Jun 1994 09:52:39 GMT
  61. Organization: University of Nevada System Computing Services
  62.  
  63. I am working through the examples in D. Mark's second Primer book using 
  64. Think C/C++ v. 6.xx.  I am trying to use CopyBits to copy a PixMap to a 
  65. window.  I think that I have typed the code in correctly and I have 
  66. looked at the appropriate header files but things are still wrong.  Here is 
  67. the code in question:
  68.  
  69. #include <Picker.h>
  70. #include <Palette.h>
  71.  
  72.     #define NIL_POINTER    0L
  73.     WindowPtr    gColorWindow;
  74.     Rect        source, dest;
  75. ...
  76. /* Setup rects and stuff */
  77. ...
  78.      CopyBits( &((CGrafPtr)gColorWindow)->portPixMap, 
  79.           &((CGrafPtr)gColorWindow)->portPixMap, 
  80.            &source, &dest, srcCopy, NIL_POINTER );        
  81.     
  82. The error that the compiler gives is:
  83.  
  84. File RColorTutor.c; Line 305
  85. Error:   first argument to function CopyBits does not match prototype
  86.  
  87. so... I look up CopyBits and find it to be:
  88.  
  89. pascal void CopyBits(const BitMap *srcBits,const BitMap *dstBits,const 
  90.     Rect *srcRect, const Rect *dstRect,short mode,RgnHandle maskRgn)
  91.  
  92. I am under the impression that with QD, CopyBits uses PixMaps the same 
  93. way as it used to use BitMaps.
  94.  
  95. I looked up an example that uses a GrafPtr cast instead of a CGrafPtr and 
  96. it works as:
  97.  
  98.     CopyBits (& ((GrafPtr)Port1)->portBits, &((GrafPtr)Port2)->portBits, 
  99.           &Rect1, &Rect2, 0, theregion);
  100.  
  101. so, I am left confused and stumped.  Could anyone tell me where I am 
  102. going wrong with my data structures?
  103.  
  104. -    Steve
  105.  
  106. +++++++++++++++++++++++++++
  107.  
  108. >From alex@metcalf.demon.co.uk (Alex Metcalf)
  109. Date: Sun, 5 Jun 1994 16:19:56 GMT
  110. Organization: Best Before Yesterday
  111.  
  112. In article <2ss797$s80@post-office.nevada.edu>, ragatz@nevada.edu (Steven
  113. Ragatz) wrote:
  114.  
  115. > I am working through the examples in D. Mark's second Primer book using 
  116. > Think C/C++ v. 6.xx.  I am trying to use CopyBits to copy a PixMap to a 
  117. > window.  I think that I have typed the code in correctly and I have 
  118. > looked at the appropriate header files but things are still wrong.  Here is 
  119. > the code in question:
  120. > #include <Picker.h>
  121. > #include <Palette.h>
  122. >     #define NIL_POINTER    0L
  123. >     WindowPtr    gColorWindow;
  124. >     Rect        source, dest;
  125. > ...
  126. > /* Setup rects and stuff */
  127. > ...
  128. >      CopyBits( &((CGrafPtr)gColorWindow)->portPixMap, 
  129. >           &((CGrafPtr)gColorWindow)->portPixMap, 
  130. >            &source, &dest, srcCopy, NIL_POINTER );        
  131. >     
  132. > The error that the compiler gives is:
  133. > File ColorTutor.c; Line 305
  134. > Error:   first argument to function CopyBits does not match prototype
  135.  
  136. Steve,
  137.  
  138.      Code looks OK: just typecast your portPixMap to a (BitMap *) like
  139. this:
  140.  
  141. CopyBits ( (BitMap *) ((CGrafPtr)gColorWindow)->portPixMap, ...
  142.  
  143.      Alex
  144.  
  145. --
  146. Alex Metcalf, Best Before Yesterday
  147. Mac programmer in C, C++, HyperTalk, assembler
  148. Juggler, 3-ball tricks
  149.  
  150. Internet:          alex@metcalf.demon.co.uk
  151. Fax (UK):          (0570) 45636
  152. Fax (US / Canada): 011 44 570 45636
  153.  
  154. +++++++++++++++++++++++++++
  155.  
  156. >From kenlong@netcom.com (Ken Long)
  157. Date: Sun, 5 Jun 1994 16:22:58 GMT
  158. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  159.  
  160. I download a working version of Dave Mark's "ColorTotor" from America 
  161. Online, a couple years ago.  It's currently in my floppy archives.  
  162. someone else could probably answer your question before I log off, get it, 
  163. log on and send you the fragment.
  164.  
  165. But I was also amazed at the similaritios between that program and one 
  166. called "CopyBits" which I got of ftp devtools.symantec.com.  I'd heard 
  167. mention of this source in a few conferences, but no one ever said where 
  168. to find it.  It's much more sophisticated and has greater scope than 
  169. Dave's little ditty.
  170.  
  171. -Ken-
  172.  
  173. +++++++++++++++++++++++++++
  174.  
  175. >From arose@ATHENA.MIT.EDU (Alex Rosen)
  176. Date: 5 Jun 1994 17:30:33 GMT
  177. Organization: Massachusetts Institute of Technology
  178.  
  179. [Confusion about copybits parameters]
  180.  
  181. Here's a message I saved from Tim Dierks from quite a while ago, which
  182. explains it very cleary.
  183. --Alex
  184.  
  185.  
  186. In article <w4s36la@rpi.edu>, raffuj@aix.rpi.edu (Jose Raffucci) wrote:
  187. > I'm really curious about what parameters should actually passed to 
  188. > copybits.  IM V and think ref 1.0 say the first two should be address 
  189. > of a pixmap or bitmap.  The examples all show :
  190. >  CopyBits(&(GrafPtr)->portBits, ...);
  191. > In IM VI however (21-19) it says that you can pass it the following:
  192. >  pixBase =  GetGWorldPixMap(world);   (pixbase is PixMapHandle)
  193. >  CoypBits( *pixBase, ...);                       
  194. > 1 worlds, and 2 doesn't.  I looked and the addresses returned for 1&2
  195. > are not the same.  close, but not quite.  I've played around with just about
  196. > every way toet the address of the pixmap for 2, and nothing works, and yes, 
  197. > I locked my handles.
  198. > Why the apparent inconsistency?  
  199.  
  200. CopyBits is definitely the wackiest call in the ToolBox.  It can accept
  201. three different kinds of parameters for its "sourceBits" and "destBits"
  202. arguments:
  203.  
  204.  - A pointer to a BitMap
  205.  - A pointer to a PixMap
  206.  - A pointer to the spot in a CGrafPort where a BitMap is supposed to be
  207.    if this port were actually a GrafPort
  208.  
  209. It's got a little song and dance it does to figure out what it's getting,
  210. but that's not important.  The weirdest thing is that you can pass in a
  211. pointer to a PixMap, which is the PixMapHandle dereferenced once.  This
  212. PixMapHandle does not have to be locked; even though CopyBits can move
  213. memory, it won't do so until after it's figured out what kind of
  214. arguments it's getting and recovered the original handle, if necessary.
  215.  
  216. I don't know if this will help you solve your problem, but it's certainly
  217. entertained me to tell you this.
  218.  
  219. Tim Dierks                                                   
  220. absurd@apple.com
  221.                   I work for MacDTS, but I speak for myself.
  222.  "If you can't lick 'em, put 'em on with a big piece of tape." -
  223. Negativland
  224.  
  225.  
  226.  
  227.  
  228. ---------------------------
  229.  
  230. >From r4650001@nickel.laurentian.ca
  231. Subject: Gestalt, SU3.0 & List Manager
  232. Date: 4 Jun 94 16:36:53 -0500
  233. Organization: Laurentian University
  234.  
  235. Does anybody know if there is a Gestalt selector code to see if System Update
  236. 3.0 is installed? Specifically, I want to know if the new LDEF used by the
  237. StandardGetFile dialog box is available. (i.e. the one that puts an icon next
  238. to the item name.) Also, I would like to know what format the data should be
  239. in when I pass a handle to LSetCell(sic).
  240.  
  241. E-mail is preferred, but if you post to the group, that's ok.
  242.  
  243. --JA
  244. R4650001@nickel.laurentian.ca
  245.  
  246. +++++++++++++++++++++++++++
  247.  
  248. >From wysocki@netcom.com (Chris Wysocki)
  249. Date: Sat, 4 Jun 1994 23:18:26 GMT
  250. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  251.  
  252. In article <1994Jun4.163653.1@nickel.laurentian.ca> r4650001@nickel.laurentian.ca writes:
  253.  
  254. >Does anybody know if there is a Gestalt selector code to see if System Update
  255. >3.0 is installed? Specifically, I want to know if the new LDEF used by the
  256. >StandardGetFile dialog box is available. (i.e. the one that puts an icon next
  257. >to the item name.)
  258.  
  259. Call Gestalt with the "gestaltStandardFileAttr" ('stdf') selector and
  260. test the "gestaltStandardFileHasColorIcons" bit (2) in the response.
  261.  
  262. >Also, I would like to know what format the data should be
  263. >in when I pass a handle to LSetCell(sic).
  264.  
  265. I don't believe that the format of the data used by the Standard File
  266. LDEF has been documented.  If this is in fact the case, I would
  267. recommend _not_ trying to reverse-engineer the format, as this is
  268. prone to breaking in the future.  Instead, write your own LDEF that
  269. does what you want.  LDEFs aren't very hard to write; I imagine that a
  270. reasonably competent Macintosh programmer could write such an LDEF in
  271. a few hours, if not less.
  272.  
  273. Chris.
  274.  
  275.  
  276. +++++++++++++++++++++++++++
  277.  
  278. >From Alexander M. Rosenberg <alexr@apple.com>
  279. Date: Mon, 6 Jun 1994 02:14:33 GMT
  280. Organization: Hackers Anonymous
  281.  
  282. In article <wysockiCqwBEq.M9B@netcom.com> Chris Wysocki, wysocki@netcom.com
  283. writes:
  284. > I don't believe that the format of the data used by the Standard File
  285. > LDEF has been documented.  If this is in fact the case, I would
  286. > recommend _not_ trying to reverse-engineer the format, as this is
  287. > prone to breaking in the future.  Instead, write your own LDEF that
  288. > does what you want.  LDEFs aren't very hard to write; I imagine that a
  289. > reasonably competent Macintosh programmer could write such an LDEF in
  290. > a few hours, if not less.
  291.  
  292. I agree with Chris.
  293.  
  294. DO NOT REVERSE ENGINEER THE SYSTEM SOFTWARE AND USE THAT INFORMATION IN YOUR
  295. APPLICATIONS! WE WILL HUNT YOU DOWN AND KILL YOU.
  296.  
  297. In this case, I was just speaking with the Software Mercenary responsible for
  298. including the Macintosh Easy Open version of Standard File in System Update
  299. 3.0. We were speaking of a way to increase the limit of items that can be
  300. displayed for a given directory. Doing so would specifically break people who
  301. "know" the format of the cell data.
  302. - -------------------------------------------------------------------------
  303. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  304. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  305. -  Palo Alto, CA 94301     -                                - Systems     -
  306. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  307. -                          - nobody cares what I say.       -             -
  308.  
  309. ---------------------------
  310.  
  311. >From mpcline@cats.ucsc.edu (Matthew Paul Cline)
  312. Subject: How to tell what kind of drive a volume is?
  313. Date: 2 Jun 1994 23:17:36 GMT
  314. Organization: University of California, Santa Cruz
  315.  
  316.  
  317.     Is there any sort of system call that will tell you the type
  318. of a volume (flopyy driver, hard drive, or other)?  Thanks in advance.
  319. -- 
  320. Poodles have no honor.               Have you hugged your shoggoth today?
  321. GE d? -p+ c++(+++) l++ u++ e+ m+ s/- n+(-) h+ f !g w+ t+ r y+
  322.  
  323. +++++++++++++++++++++++++++
  324.  
  325. >From mclow@coyote.csusm.edu (Marshall Clow)
  326. Date: 2 Jun 1994 16:59:01 -0700
  327. Organization: California State University San Marcos
  328.  
  329. Matthew Paul Cline (mpcline@cats.ucsc.edu) wrote:
  330.  
  331. >    Is there any sort of system call that will tell you the type
  332. >of a volume (flopyy driver, hard drive, or other)?  Thanks in advance.
  333.  
  334. Not in general, but you can infer a lot about a volume from looking
  335. at a few bits of information.
  336.  
  337. 1) What driver talks to it? Is it '.Sony'? Then it's a floppy.
  338. 2) Is the driver in the range for SCSI devices?
  339. 3) Is the volume read-only?
  340. 4) Is the volume ejectable?
  341. 5) Is the volume "remote"?
  342. .. and so on.
  343.  
  344. None of the information is conclusive, but you can figure out what
  345. you need to know >95% of the time.
  346.  
  347. Marshall Clow
  348. Aladdin Systems
  349. mclow@san_marcos.csusm.edu
  350.  
  351.  
  352. +++++++++++++++++++++++++++
  353.  
  354. >From Jerry.Halstead@launchpad.unc.edu (jerry halstead)
  355. Date: 3 Jun 1994 00:45:39 GMT
  356. Organization: University of North Carolina Extended Bulletin Board Service
  357.  
  358. reply to message from mpcline@cats.ucsc.edu:
  359.  
  360. I got some help last week correlating between a vRefNum and the actual
  361. SCSI ID.  I used PBHGetVInfo to get the refnum and the following formula
  362. to convert to a SCSI ID:
  363.  
  364.  HParamBlockRec    volPB;
  365.  volPB.volumeParam.ioVRefNum = 0;
  366.  volPB.volumeParam.ioNamePtr = (StringPtr)name;
  367.  volPB.volumeParam.ioVolIndex = i;   // this is in a loop to get all drivers
  368. if (PBHGetVInfo(&volPB,FALSE) == noErr){        
  369.    RefNum = abs(volPB.volumeParam.ioVDRefNum+1);
  370.    scsiID = RefNum-32;  }
  371.  
  372. I then use the scsiID with the SCSI manager routines to obtain Inquiry data
  373. for the given drive, which includes, among other things, the device type. 
  374. Here's the beginnings of the device type table from the SCSI spec:
  375.  
  376. ____SCSI_Dev_types___
  377. direct access (disk) 0
  378. seq access (tape)    1
  379. printer device       2
  380. processor            3
  381. worm                 4
  382. cd-rom               5
  383.  
  384. Of course this may not be the level of implementation you had in mind. 
  385. Hope it helps.
  386.  
  387.  
  388. Big head Jerry and the demonstrables....
  389. --
  390. - ----------------------------------------------------------------------------
  391.  \ The above does not represent OIT, UNC-CH, laUNChpad, or its other users. /
  392.    ------------------------------------------------------------------------
  393.  
  394. +++++++++++++++++++++++++++
  395.  
  396. >From blob@apple.com (Brian Bechtel)
  397. Date: 4 Jun 1994 07:00:36 -0700
  398. Organization: Apple Computer, Inc., Cupertino, California
  399.  
  400. mclow@coyote.csusm.edu (Marshall Clow) writes:
  401.  
  402. >Matthew Paul Cline (mpcline@cats.ucsc.edu) wrote:
  403.  
  404. >>    Is there any sort of system call that will tell you the type
  405. >>of a volume (flopyy driver, hard drive, or other)?  Thanks in advance.
  406.  
  407. >Not in general, but you can infer a lot about a volume from looking
  408. >at a few bits of information.
  409.  
  410. >1) What driver talks to it? Is it '.Sony'? Then it's a floppy.
  411.  
  412. Or an HD 20.  Or something which is trying to emulate either a floppy or
  413. an HD 20.  (The HD 20 was the first Apple-labeled Macintosh hard drive.
  414. It did not use SCSI.)
  415.  
  416. >2) Is the driver in the range for SCSI devices?
  417.  
  418. With Asynchronous SCSI Manager 4.3, SCSI devices have can drivers
  419. outside the traditional range.
  420.  
  421. >3) Is the volume read-only?
  422. >4) Is the volume ejectable?
  423. >5) Is the volume "remote"?
  424. >.. and so on.
  425.  
  426. >None of the information is conclusive, but you can figure out what
  427. >you need to know >95% of the time.
  428.  
  429. Yup.
  430.  
  431. --Brian Bechtel     blob@apple.com     "My opinion, not Apple's"
  432.  
  433. +++++++++++++++++++++++++++
  434.  
  435. >From dshayer@netcom.com (David Shayer)
  436. Date: Sun, 5 Jun 1994 22:36:37 GMT
  437. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  438.  
  439. Brian Bechtel (blob@apple.com) wrote:
  440. : mclow@coyote.csusm.edu (Marshall Clow) writes:
  441. : >Matthew Paul Cline (mpcline@cats.ucsc.edu) wrote:
  442. : >>    Is there any sort of system call that will tell you the type
  443. : >>of a volume (flopyy driver, hard drive, or other)?  Thanks in advance.
  444. : >1) What driver talks to it? Is it '.Sony'? Then it's a floppy.
  445. : Or an HD 20.  Or something which is trying to emulate either a floppy or
  446. : an HD 20.  (The HD 20 was the first Apple-labeled Macintosh hard drive.
  447. : It did not use SCSI.)
  448.  
  449. You can tell a floppy from an HD20 by driver refnum.  The floppy driver
  450. has refnum -5, while the hd20 driver has refnum -2.
  451.  
  452.  
  453. +------------------------------------------------------------------------+
  454. |David Shayer                                  (415) 595-2523            |
  455. |Sentient Software / Symantec                  shayer@applelink.apple.com|
  456. |"Subvert the Dominant Paradigm."              Applelink: SHAYER         |
  457. +------------------------------------------------------------------------+
  458.  
  459.  
  460. ---------------------------
  461.  
  462. >From idowell@bbn.com (Ian Dowell)
  463. Subject: Photoshop Plug-in Filters useable with other programs?
  464. Date: 7 Jun 94 04:35:24 GMT
  465. Organization: Bolt, Beranek and Newman Inc.
  466.  
  467. Are Photoshop Plug-in Filters useable with other programs? 
  468. Is it possible to write a program which could use the filters
  469. to do transformations?
  470. Is there any documentation or example code available?
  471.  
  472. Thanks in advance!
  473. Ian
  474. -- 
  475. - ----------------------------------------------------------------------
  476. Ian Dowell            Bolt, Beranek & Newman, Cambridge, MA
  477. idowell@bbn.com       (617) 873-2673
  478.  
  479. +++++++++++++++++++++++++++
  480.  
  481. >From tgaul@halcyon.com (Troy Gaul)
  482. Date: Mon, 06 Jun 1994 22:35:41 -0700
  483. Organization: Infinity Systems
  484.  
  485. In article <idowell.770963724@labs-n.bbn.com>, idowell@bbn.com (Ian Dowell)
  486. wrote:
  487.  
  488. > Are Photoshop Plug-in Filters useable with other programs? 
  489. > Is it possible to write a program which could use the filters
  490. > to do transformations?
  491. > Is there any documentation or example code available?
  492.  
  493. Photoshop filters, in general, are usable by other programs.  To write such
  494. a program, simply follow the interface given in the Adobe plug-in
  495. specification files (the same ones you need if you're writing plug-ins). 
  496. You can find this specification in various places online, including from
  497. anonymous FTP at:
  498.  
  499. ftp://export.acs.cmu.edu//pub/PSarch/misc-mac/PS2.5Developers_Kit.cpt.hqx
  500.  
  501. The plug-ins _included_ with Photoshop, however, are not usable by other
  502. programs because of a passwording sceme they use to verify that they are
  503. talking to Photoshop.
  504.  
  505. _troy
  506. //////// //////___Troy Gaul_________________________tgaul@halcyon.com__ //
  507.   //    //       Infinity Systems ; Redmond, Washington                //
  508.  //    //  //  "Insert witty quote here."                             //
  509. //    //////________________________________________________________ //
  510.  
  511. ---------------------------
  512.  
  513. >From Ken Prehoda <kenp@nmrfam.wisc.edu>
  514. Subject: Scheduling Sleep in WaitNextEvent
  515. Date: 4 Jun 1994 02:54:55 GMT
  516. Organization: Univ of Wisc-Madison
  517.  
  518. I have a number of questions concerning calling WaitNextEvent.
  519.  
  520. First, it has been mentioned that WaitNextEvent should
  521. only be called about once a second (possibly when
  522. you aren't doing anything).  What is the best way to accomplish
  523. this?
  524.  
  525. Second, what is the best way to schedule the sleep
  526. parameter?  I can envision four situations that may
  527. require different values for sleep:
  528.  
  529. 1) I'm in the foreground and doing something.
  530.  
  531. 2) I'm in the foreground and doing nothing.
  532.  
  533. 3) I'm in the background doing something.
  534.  
  535. 4) I'm in the background doing nothing.
  536.  
  537. What are the best values in these situations?
  538.  
  539. Thanks,
  540. Ken Prehoda
  541. kenp@nmrfam.wisc.edu
  542.  
  543. +++++++++++++++++++++++++++
  544.  
  545. >From rmah@panix.com (Robert S. Mah)
  546. Date: Fri, 03 Jun 1994 23:38:47 -0500
  547. Organization: One Step Beyond
  548.  
  549. Ken Prehoda <kenp@nmrfam.wisc.edu> wrote:
  550.  
  551. > I have a number of questions concerning calling WaitNextEvent.
  552. > First, it has been mentioned that WaitNextEvent should only be called
  553. > about once a second (possibly when you aren't doing anything).  What 
  554. > is the best way to accomplish this?
  555.  
  556. Not exactly.  When people refered to fixed-time calling of WNE it was in
  557. the context of executing computationally intensive code and still giving
  558. time to other apps.  IOW, being a nice coop multi-tasking app (NCMTA).
  559.  
  560. When you're not doing anything that's computationally intensive, that is,
  561. you don't need idle time, just give the sleep value something really big.
  562.  
  563. What will happen is that any time you're app gets a real event such as
  564. a mouse down or an update, WNE will return immediately after the event is
  565. posted (as long as the other apps are NCMTA's) so you can handle it.
  566.  
  567. If you're app doesn't need to do anything (i.e. there are no events
  568. pending),
  569. then WNE won't bother returning until either 1) the sleepTime has passed or
  570. 2) none of the other apps need to do anything either.
  571.  
  572. To sum up.  The sleep parameter is a _suggestion_ to WNE about how much
  573. time
  574. you need between idle events.  WNE may return before it has elapsed if the
  575. machine is not busy.  It may return after it has elapsed if the machine is
  576. really busy.  The fixed-timing technique for calling WNE is to assure your
  577. app gets a large timeslice when it is executing some critical and intensive
  578. code.
  579.  
  580. Cheers,
  581. Rob
  582. ___________________________________________________________________________
  583. Robert S. Mah  -=-  One Step Beyond  -=-  212-947-6507  -=-  rmah@panix.com
  584.  
  585. +++++++++++++++++++++++++++
  586.  
  587. >From j-norstad@nwu.edu (John Norstad)
  588. Date: Fri, 03 Jun 1994 23:11:44 -0500
  589. Organization: Northwestern University
  590.  
  591. In article <2soqdv$jeu@news.doit.wisc.edu>, Ken Prehoda
  592. <kenp@nmrfam.wisc.edu> wrote:
  593.  
  594. > I have a number of questions concerning calling WaitNextEvent.
  595. > First, it has been mentioned that WaitNextEvent should
  596. > only be called about once a second (possibly when
  597. > you aren't doing anything).  What is the best way to accomplish
  598. > this?
  599. > Second, what is the best way to schedule the sleep
  600. > parameter?  I can envision four situations that may
  601. > require different values for sleep:
  602. > 1) I'm in the foreground and doing something.
  603. > 2) I'm in the foreground and doing nothing.
  604. > 3) I'm in the background doing something.
  605. > 4) I'm in the background doing nothing.
  606. > What are the best values in these situations?
  607.  
  608. These are very good and very difficult questions, and not everyone agrees
  609. on the answers. (I just had a debate about this issue with Leonard
  610. Rosenthol today, in fact.)
  611.  
  612. Here's what I do, in three different circumstances:
  613.  
  614. (1) In my main event loop, when my program is idle, I call WNE with sleep
  615. = GetCaretTime(). This gives other non-idle processes plenty of time, and
  616. in the case where I'm in the foreground and my active window includes a
  617. text editing field, it keeps my caret blinking. I also pass a mouseRgn
  618. parameter to WNE in this call, to get woken up immediately if I'm in the
  619. foreground and the user moves the mouse and I need to adjust the cursor.
  620.  
  621. (2) During CPU-intensive tasks, I call a "GiveTime" function periodically.
  622. This function calls WNE once every five ticks with sleep=0 and
  623. mouseRgn=nil. It handles at least update, activate, suspend, and resume
  624. events. It also checks for user cancel actions (Command-period, Escape,
  625. click on Cancel button in status window, or whatever). It also keep my
  626. animated cursor spinning.
  627.  
  628. It's important to throttle your WNE calls in this case. Your GiveTime
  629. function should only call WNE every 4-6 ticks (Apple-recommended values).
  630. This avoids excessive process switching (thrashing), gives other
  631. CPU-intensive tasks plenty of time, makes the foreground process
  632. responsive to user actions when you are in the background, doesn't slow
  633. you down noticeable on an otherwise idle system, gives excellent response
  634. to user cancel operations, gives a smoothly animated cursor, and provides
  635. uniform behavior independent of CPU speed. It's a good balance.
  636.  
  637. You mentioned only calling WNE once per second (60 ticks). That's way too
  638. long - you are really hogging the CPU. 5 ticks is much more appropriate.
  639.  
  640. (3) When waiting for a network task to complete (e.g., during an
  641. asynchronous MacTCP send or receive call, while I'm polling the result
  642. code in the parameter block), I call WNE continuously with sleep=0 and
  643. mouseRgn=nil. The difference between (2) and (3) is that (3) doesn't
  644. throttle the WNE calls to every 5 ticks. This is because I have nothing to
  645. compute in this case, so I want to yield to other processes immediately to
  646. let them use the available CPU time while I'm waiting. I use the same
  647. GiveTime function as in (2), but I pass a parameter telling it to call WNE
  648. even if the 5 ticks hasn't expired.
  649.  
  650. Notice that I don't do anything special when I'm in the background - the
  651. algorithm is the same. Some people use a non-zero sleep time when they're
  652. in the backgound doing CPU-intensive tasks. This slows you down quite a
  653. bit, even on an otherwise idle system, and I think it's wrong. The correct
  654. way to yield time to other processes when you are in the background is to
  655. make certain you call WNE at least every 5 ticks, not to use a non-zero
  656. sleep time. Indeed, this is always the correct way to yield time to other
  657. processes, and being in background or in the foreground really doesn't
  658. matter.
  659.  
  660. As an example, here's my GiveTime function in NewsWatcher:
  661.  
  662. /*----------------------------------------------------------------------------
  663.    GiveTime
  664.    
  665.    Give time to other processes during long operations and check for 
  666.    user cancels.
  667.    
  668.    Entry:   waiting = true if waiting for MacTCP or something else.
  669.    
  670.    Exit:    function result = error code (userCanceledErr if canceled
  671.                by user, else noErr).
  672. - --------------------------------------------------------------------------*/
  673.  
  674. OSErr GiveTime (Boolean waiting)
  675. {
  676.    EventRecord ev;
  677.    Boolean gotEvt;
  678.    static long nextTime = 0;
  679.       
  680.    if (!gLongOperation) {
  681.       HiliteMenu(0);
  682.       SpinCursor(0);
  683.       ShowCursor();
  684.       gLongOperation = true;
  685.    }
  686.  
  687.    if (TickCount() >= nextTime) {
  688.       SpinCursor(16);
  689.       nextTime = TickCount() + 5;
  690.       waiting = true;
  691.    }
  692.  
  693.    if (waiting) {
  694.       gotEvt = WaitNextEvent(everyEvent, &ev, 0, nil);
  695.       if (gotEvt) HandleEvent(&ev);
  696.    }
  697.    
  698.    return gCancel ? userCanceledErr : noErr;
  699. }
  700.  
  701. The "HandleEvent" function is the same event handling function called by
  702. my main event loop.
  703.  
  704. "gCancel" is a global variable which is set to true by my event handlers
  705. when a user cancel event occurs.
  706.  
  707. "gLongOperation" is a global variable which records whether I'm busy doing
  708. something or idle. Some of the event handlers need to know this
  709. information.
  710.  
  711. I hope this is interesting and helps.
  712.  
  713. -- 
  714. John Norstad
  715. Academic Computing and Network Services
  716. Northwestern University
  717. j-norstad@nwu.edu
  718.  
  719. +++++++++++++++++++++++++++
  720.  
  721. >From jumplong@aol.com (Jump Long)
  722. Date: 4 Jun 1994 23:42:05 -0400
  723. Organization: America Online, Inc. (1-800-827-6364)
  724.  
  725. In article <j-norstad-0306942311440001@aragorn12.acns.nwu.edu>,
  726. j-norstad@nwu.edu (John Norstad) writes:
  727.  
  728. >(3) When waiting for a network task to complete (e.g., during an
  729. >asynchronous MacTCP send or receive call, while I'm polling the
  730. result
  731. >code in the parameter block), I call WNE continuously with sleep=0
  732. and
  733. >mouseRgn=nil...
  734.  
  735. If you're waiting for an asynchronous request to complete with a
  736. completion routine, then you can have the completion routine call
  737. WakeUpProcess using your application's process serial number.  That
  738. way, you can give up more time to other processes and still have your
  739. application awaken when it needs to be awakened.
  740.  
  741. - Jim Luther
  742.  
  743.  
  744. +++++++++++++++++++++++++++
  745.  
  746. >From j-norstad@nwu.edu (John Norstad)
  747. Date: Sun, 05 Jun 1994 08:48:16 -0500
  748. Organization: Northwestern University
  749.  
  750. In article <2srhid$572@search01.news.aol.com>, jumplong@aol.com (Jump
  751. Long) wrote:
  752.  
  753. > If you're waiting for an asynchronous request to complete with a
  754. > completion routine, then you can have the completion routine call
  755. > WakeUpProcess using your application's process serial number.  That
  756. > way, you can give up more time to other processes and still have your
  757. > application awaken when it needs to be awakened.
  758.  
  759. But then you can't poll for user cancel events, which is very important
  760. when waiting for long network requests to complete.
  761.  
  762. -- 
  763. John Norstad
  764. Academic Computing and Network Services
  765. Northwestern University
  766. j-norstad@nwu.edu
  767.  
  768. ---------------------------
  769.  
  770. >From Paul Goyette <goyettep@ccnet.com>
  771. Subject: What is "Clipping Extension"?
  772. Date: 5 Jun 1994 15:17:58 GMT
  773. Organization: (none)
  774.  
  775. The title says it all - I've installed the Drag&Drop stuff, and when I
  776. reboot the Mac,
  777. I get a message that the Clipping Extension cannot be used because it is
  778. "too new".
  779.  
  780. So, what is this Cliping Extension, and what version of what program do I
  781. need to
  782. be able to use it?
  783.  
  784. - ---------------------------------------------------------
  785. Paul Goyette        |  PGP Public key available on request 
  786. goyettep@ccnet.com  |  Fingerprint: 54 03 19 EE 99 57 FB 79
  787.                     |               74 0A D0 E6 BE 84 0E DA
  788. - ---------------------------------------------------------
  789.  
  790. +++++++++++++++++++++++++++
  791.  
  792. >From Richard Cardona <rickc@mail.utexas.edu>
  793. Date: 5 Jun 1994 17:43:21 GMT
  794. Organization: UT-Austin
  795.  
  796. In article <2ssqb6$apf@ccnet.ccnet.com> Paul Goyette, goyettep@ccnet.com
  797. writes:
  798. >So, what is this Cliping Extension, and what version of what program do I
  799. >need to
  800. >be able to use it?
  801.  
  802. In System 7.0.x, you need to run Macintosh Drag and Drop and the clipping
  803. extension to have full clipping files support.  What are clipping files? 
  804. They are Drag and Drop data the finder can support and create files out
  805. of.  Right now I believe the Finder only supports text, pictures and
  806. sound.  Moovs are in the works.  With the clipping extension, the finder
  807. can even open the clipping files and show you what they contain - neato!
  808. Example, highlight a piece of text from SimpleText and drag it over to
  809. the Finder, release it, and the Finder will create a text clipping file. 
  810. You must have the clipping extension to do this.  Similarly, a text
  811. clipping file can be dragged back into Simpletext and "pasted."
  812.  
  813. In System 7.5,the clipping extension is useless and built in to the
  814. Finder, but you still need the Drag and Drop extension for now.
  815.  
  816. I suggest you get a copy of both the Drag and Drop extension 1.1 and the
  817. Clipping extension from June's Developer CD.  The documentation is also a
  818. little confusing, claiming you need Finder 7.1.3 also.  (7 Pro's Finder
  819. is 7.1.4)  But, I know this combo works together (at least on a
  820. Powermac).  I don't have an on-line ftp site for the clipping extension,
  821. anyone? The WWDC contains the Drag and Drop extension for 7.5 I don't
  822. recommend this version for use without 7.5.
  823.  
  824. Rick
  825.  
  826. +++++++++++++++++++++++++++
  827.  
  828. >From Jens Alfke <jens_alfke@powertalk.apple.com>
  829. Date: Mon, 6 Jun 1994 20:29:54 GMT
  830. Organization: Apple Computer
  831.  
  832. Paul Goyette, goyettep@ccnet.com writes:
  833. > So, what is this Cliping Extension, and what version of what program do I
  834. > need to
  835. > be able to use it?
  836.  
  837. You need Finder 7.1.3 or 7.1.4. (7.1.4 is identical to 7.1.3 except for the
  838. size of a text field in the 'About This Mac' window, to support the
  839. PowerMacs.)
  840.  
  841. Richard Cardona, rickc@mail.utexas.edu writes:
  842. > Right now I believe the Finder only supports text, pictures and
  843. > sound.  Moovs are in the works.
  844.  
  845. The Finder will make clipping files out of any kind of data an application
  846. can drop, and you can then take those clippings and drop them into another
  847. app. The only type limitations are what kinds of clippings the Finder can
  848. open up and display -- only text and pict, right now.
  849.  
  850. > I suggest you get a copy of both the Drag and Drop extension 1.1 and the
  851. > Clipping extension from June's Developer CD.
  852.  
  853. D&D 1.1 is also on the bookmark CD with 'develop' 18. This includes Finder
  854. 7.1.3.
  855.  
  856. --Jens Alfke
  857.   jens_alfke@powertalk              Rebel girl, rebel girl,
  858.             .apple.com              Rebel girl you are the queen of my world
  859.  
  860. ---------------------------
  861.  
  862. >From valentin+@pitt.edu (Shawn V. Hernan)
  863. Subject: allocating memory quickly -- how?
  864. Date: 2 Jun 1994 20:28:04 GMT
  865. Organization: The University of Pittsburgh
  866.  
  867. Greetings all, 
  868.  
  869.  
  870.      I want to allocate a large array (1000 elements) of pointers to
  871. characters the beginning of a program (it makes sense to do it this way
  872. in this case) . So, in a loop, I have code that looks like the
  873. following:
  874.  
  875.     array[i][j] = NewPtrClear(80);
  876.  
  877.     I have a similar Unix and VMS program that uses malloc in the same
  878. way I use NewPtr above. All three programs work pretty well, excpet
  879. that allocating the memory on the Macintosh is VERY SLOOOOOOW. Is there
  880. a faster way to allocate lots of little chunks of memory than NewPtr?
  881. malloc dies a cold death on the Mac, and I don't know why. I've looked
  882. through the faq's with no luck. 
  883.  
  884.  
  885.        Any help is deeply appreciated. 
  886.  
  887. Thanks, 
  888. Shawn
  889.  
  890.  
  891.  
  892.  
  893. Shawn Valentine Hernan       |Is the War on Drugs worth it?  
  894. The University of Pittsburgh |Why does the government want your guns?  
  895. valentin+@pitt.edu           |Does RICO ring a bell?   
  896. 412-624-6425                 |Did you vote in the last election?
  897.  
  898. +++++++++++++++++++++++++++
  899.  
  900. >From mgr@aggroup.aggroup.com (Mike Russell)
  901. Date: Thu, 02 Jun 1994 15:36:06 -0800
  902. Organization: the ag group, inc.
  903.  
  904. In article <2slfcl$78r@usenet.srv.cis.pitt.edu>, valentin+@pitt.edu (Shawn
  905. V. Hernan) wrote:
  906. >      I want to allocate a large array (1000 elements) of pointers to
  907. > characters the beginning of a program (it makes sense to do it this way
  908. >     array[i][j] = NewPtrClear(80);
  909.  
  910. try allocating one giant block instead:
  911.  
  912.  char *p = NewPtrClear(80L * height * width);
  913.  
  914. then in your loop
  915.  
  916.  array[i][j] = p + ((long)i * (long)j) * 80L;
  917.  
  918. As for why - the reason goes back to the original tiny Mac that the
  919. Memory Manager was designed for.  Call it a homage to history.
  920.  
  921. +++++++++++++++++++++++++++
  922.  
  923. >From stk@uropax.contrib.de (Stefan Kurth)
  924. Date: 3 Jun 1994 04:06:01 +0200
  925. Organization: Contributed Software GbR
  926.  
  927. In article <2slfcl$78r@usenet.srv.cis.pitt.edu>,
  928. Shawn V. Hernan <valentin+@pitt.edu> wrote:
  929.  
  930. > that allocating the memory on the Macintosh is VERY SLOOOOOOW. Is there
  931. > a faster way to allocate lots of little chunks of memory than NewPtr?
  932.  
  933. NewHandle might be a little bit faster than NewPtr, depending on how many
  934. relocatable blocks you have in your heap; however, I doubt that the
  935. difference will be very big.
  936.  
  937. > malloc dies a cold death on the Mac, and I don't know why.
  938.  
  939. What problems do you have with malloc?
  940.  
  941. In the program that I'm currently writing, I have to deal with
  942. ten-thousands of very small blocks; at first I used handles for all of
  943. them, because, well, we're on a Mac, and "one uses" handles on a Mac. Later
  944. I have changed all the code to use malloc instead, and some portions of the
  945. program are now more than twice as fast (especially the routines that
  946. allocate lots of blocks). I'm not very happy about the fact that free()
  947. never releases the memory that has been allocated, but speed is more
  948. important for me than that (in this case at least - normally I don't use
  949. malloc in my programs).
  950.  
  951. ________________________________________________________________________
  952. Stefan Kurth                 Berlin, Germany              stk@contrib.de
  953.  
  954. +++++++++++++++++++++++++++
  955.  
  956. >From rang@winternet.com (Anton Rang)
  957. Date: 04 Jun 1994 23:45:19 GMT
  958. Organization: Minnesota Angsters
  959.  
  960. In article <coopem-030694133005@coopem.dialup.access.net> coopem@panix.com (Marc Cooperman) writes:
  961. >In my limited experience in mac programming, I read somewhere that the Mac
  962. >memory manager was designed to manage a system with small memory (like 128K
  963. >- remember that). So basically any memory operation can cause the heap to
  964. >be compacted - the mac is trying to optimize memory utilization and
  965. >minimize fragmentation.
  966.  
  967.   This is true to some extent.  If you use pointers much, you'll get
  968. quite a lot of memory shuffling, because the memory manager tries to
  969. keep all of the non-relocatable blocks together.  If you use handles
  970. instead, and call MaxApplZone() at the beginning of your program,
  971. there won't be too much shuffling going on.
  972.  
  973.   I should also note that I got some information in the mail a couple
  974. of months ago from a company that makes a replacement for the whole
  975. malloc()/newptr()/newhandle() suite.  I think it's called SmartHeap.
  976. Looked pretty interesting, for programs which need to do a *lot* of
  977. memory allocation.
  978. --
  979. Anton Rang (rang@winternet.com)
  980.  
  981. +++++++++++++++++++++++++++
  982.  
  983. >From shawn@greebe (shawn@mdli.com)
  984. Date: Mon, 6 Jun 1994 16:43:15 GMT
  985. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  986.  
  987. Shawn V. Hernan (valentin+@pitt.edu) wrote:
  988. > malloc dies a cold death on the Mac, and I don't know why. I've looked
  989. > through the faq's with no luck.
  990.  
  991. Assuming that you are using Think C, the dead malloc may actually be a 
  992. problem where you might be overrunning the limits of your allocated
  993. block. In Think C this can corrupt the next structure in such a way that
  994. is frequently locks up the machine at the next memory allocation call
  995. which tries to use this memory. Is it possible that you are trying to
  996. store 80 character strings in those character pointers ? The terminating
  997. null would them blow out the next allocation and cause just this sort
  998. of behavior.
  999.  
  1000. This is a long standing Think C behavior and lots of people have run into
  1001. it, not really a bug (you are after all overrunning your allocation), 
  1002. but quite annoying.
  1003.  
  1004. I agree with the original poster about allocation of a single large block
  1005. and then assigning the addresses, this is often faster. Think actually uses
  1006. a variation of this for malloc.
  1007.  
  1008. Shawn Lavin (shawn@mdli.com)
  1009. As always, my opinions are my own
  1010.  
  1011.  
  1012. ---------------------------
  1013.  
  1014. >From brandyn@apple.com (Brandyn Webb)
  1015. Subject: sqrti() [Re: Faster Square Root Algorithm]
  1016. Date: 27 May 1994 16:28:39 -0700
  1017. Organization: Apple Computer Inc, Cupertino, CA
  1018.  
  1019.     Here's the integer sqrt() code I use; it looks similar to
  1020. some others posted, but may be a little faster (or slower; who
  1021. knows).  Hope someone finds it useful:
  1022.  
  1023.  
  1024. #define iterate(e)            \
  1025.     y <<= 1;                \
  1026.     temp = (y|1)<<(2*e);    \
  1027.     if (temp <= X) {        \
  1028.         y |= 2;                \
  1029.         X -= temp;             \
  1030.     }                 
  1031.  
  1032. unsigned sqrti(X)
  1033. register unsigned X;
  1034. {
  1035.     register unsigned yy, y, temp;
  1036.  
  1037.     y = 0;
  1038.     iterate(15); iterate(14); iterate(13); iterate(12);
  1039.     iterate(11); iterate(10); iterate(9); iterate(8);
  1040.     iterate(7); iterate(6); iterate(5); iterate(4);
  1041.     iterate(3); iterate(2); iterate(1); iterate(0);
  1042.     return y>>1;
  1043. }
  1044.  
  1045.  
  1046.     -Brandyn (brandyn@brainstorm.com)
  1047.  
  1048.  
  1049. +++++++++++++++++++++++++++
  1050.  
  1051. >From lakeland@mu.sans.vuw.ac.nz (Corrin Lakeland)
  1052. Date: 6 Jun 1994 00:55:23 GMT
  1053. Organization: SANS, Victoria University of Wellington, New Zealand.
  1054.  
  1055. > [Another SQRT routine]
  1056.  
  1057. I was just wondering, would it not be faster to set up a log table in 
  1058. memory and use that for calculating square roots.  Depending on how much 
  1059. speed and or accuracy you need you could change the table (speed = 
  1060. greater range, accuricy = more choices).  This should be very fast to 
  1061. look up if you are doing square roots extensivly - otherwise the memory 
  1062. use would make it not worth while.  
  1063.  
  1064. Disclaimer : I have not tested this meathod for speed, while it will 
  1065. work, it may turn out to be slower or use excessive amounts of ram.
  1066.  
  1067. Corrin Lakeland (lakeland@mu.sans.vuw.ac.nz)
  1068.  
  1069. +++++++++++++++++++++++++++
  1070.  
  1071. >From afcjlloyd@aol.com (AFC JLloyd)
  1072. Date: 6 Jun 1994 02:51:02 -0400
  1073. Organization: America Online, Inc. (1-800-827-6364)
  1074.  
  1075. In article <2sts5r$41e@st-james.comp.vuw.ac.nz>,
  1076. lakeland@mu.sans.vuw.ac.nz (Corrin Lakeland) writes:
  1077.  
  1078. >> [Another SQRT routine]
  1079. >
  1080. >I was just wondering, would it not be faster to set up a log table
  1081. in 
  1082. >memory and use that for calculating square roots.  Depending on how
  1083. much 
  1084. >speed and or accuracy you need you could change the table (speed = 
  1085. >greater range, accuricy = more choices).  This should be very fast
  1086. to 
  1087. >look up if you are doing square roots extensivly - otherwise the
  1088. memory 
  1089. >use would make it not worth while.  
  1090. >
  1091. >Disclaimer : I have not tested this meathod for speed, while it will
  1092.  
  1093. >work, it may turn out to be slower or use excessive amounts of ram.
  1094.  
  1095. If you're willing to use a table lookup method, a technique that I
  1096. have found to be very fast is to compute a table of square roots and
  1097. use entries from it to seed Newton-Raphson.  The trick is to estimate
  1098. Log2(N) by finding the topmost set bit of N.  Then use this estimate
  1099. to "normalize" N into an index in the lookup table, lookup the value,
  1100. and then "denormalize" the value back into the correct range.  Once
  1101. you have this estimate, you only need a very small number of
  1102. iterations.  For example, a table of 128 values provides initial
  1103. seeds accurate enough to compute the square root of a 32-bit integer
  1104. in just one iteration of Newton-Raphson.  The same table can be used
  1105. to do Fixed or Fract square roots in two iterations each.  If a table
  1106. of 128 values is too large then you can reduce the table down to 32
  1107. (maybe 16) entries and then do one more iteration of Newton-Raphson.
  1108.  
  1109. Jim Lloyd
  1110. afcjlloyd@aol.com
  1111.  
  1112.  
  1113. ---------------------------
  1114.  
  1115. End of C.S.M.P. Digest
  1116. **********************
  1117.  
  1118.  
  1119. ˇ